﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<GalleryCategoryListPaginationViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
    <title>
        <%= Model.Localize("CategoriesPageTitle")%></title>
    <%= Html.GetCssFile(Url.GetModuleCssPath("MvcEngine.Gallery.BackOffice.css")) %>
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <div class="page-title" id="post-header">
        <h1>
            <%= Model.Localize("CategoriesPageHeader")%></h1>
    </div>
    <div class="page-menu">
        <%= Html.UrlActionLink(Model.Localize("BackLink"), Url.Gallery(Model.GalleryName))%>
        |
        <%= Html.UrlActionLink(Model.Localize("NewLink"), "javascript:void(0);", "EditCategory(false,'" + Url.NewCategory() + "');return false;")%>|
    </div>
    <div>
        <% if (!Model.IsCorrectPage) 
           {
           %>
           <%= Model.Localize("CategoryInvalidPage")%>
           <%
           }
           else if(Model.Categories.Count > 0)
           { %>
        <%= Html.Grid(Model.Categories).Columns(column =>
        {
            column.For(x => Html.UrlActionLink(Html.Image(Url.ImagePath("edit.gif"), Model.Localize("EditAltText")), "javascript:void(0);", "EditCategory(true, '" + Url.EditCategory(x.Id) + "');return false;", false) +
                Html.PostActionLink(Html.Image(Url.ImagePath("delete.gif"), Model.Localize("DeleteAltText")), Url.DeleteCategory(x.Id), Html.DeleteConfirmDialog(), false))
           .Header(Model.Localize("ActionsLabel")).DoNotEncode();
            column.For(x => x.Name).Named(Model.Localize("NameColumn"));
            column.For(x => x.Slug).Named(Model.Localize("SlugColumn"));
            column.For(x => x.Visible).Named(Model.Localize("VisibleColumn"));
            column.For(x => x.CreatedDate);
            column.For(x => x.ModifiedDate);
        }).Attributes(cellSpacing => "0", cellPadding => "0", border => "0")
        .Footers(footer =>
          {
              footer.For(Model.Localize("PagesLabel") + Model.TotalPages.GetPaging(p => Html.UrlActionLink(p.ToString(), Url.GalleryCategories(p)) + "&nbsp;")).DoNotEncode().Attributes(colspan => "5");
              footer.For(string.Format(Model.Localize("TotalItems"), Model.TotalItems));
          })%>
        <%}
           else
           { %>
        <%= Model.Localize("CategoryEmptyListMessage")%>
        <%} %>
    </div>
    <div id="dialog">
    </div>
    
    <script type="text/javascript">

        function EditCategory(isEdit, url) {
            $('#dialog').dialog("destroy");
            if (isEdit)
                $('#dialog').attr("title", '<%=Model.Localize("EditCategoryTitle")%>');
            else 
                $('#dialog').attr("title", '<%=Model.Localize("NewCategoryTitle")%>');

            $.get(url, null, function(data) {
                $('#dialog').html("");
                $('#dialog').html(data);
                $('#dialog').dialog('open');
            }, "text");
        }

    </script>        
</asp:Content>
